
package org.atm.domain;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * 
 */
@Entity
@Table(name = "ATMCard")
@SecondaryTable(name="USERTABLE",
    pkJoinColumns=@PrimaryKeyJoinColumn(name="USER_ID"))
public class ATMCard implements Serializable {
    public static final String APPROVED = "Approved";
    public static final String NEW = "New";
    public static final String REJECTED = "Rejected";
    private static final long serialVersionUID = 1L;
    
    @Id @GeneratedValue(strategy= GenerationType.TABLE)
    @Basic(optional = false)
    @Column(name = "CARD_ID")
    private Integer id;
    
    @Column(table="USERTABLE", name="USERNAME")
    private String cardNumber;
    
    @Column(table="USERTABLE", name="PASSWORD")
    private String PIN;
    
    @Column(name = "EXPIRYDATE")
    @Temporal(TemporalType.DATE)
    private Date expiryDate;
    
    @Column(name = "STATUS", nullable=false)
    private String status;

    @OneToOne(mappedBy="ATMCard")
    private Client client;

    public ATMCard() {
    }

    public ATMCard(Integer id) {
        this.id = id;
    }

    @PrePersist
    private void setDefaults() {
        this.status = NEW;
    }

    public Integer getId() {
        return id;
    }

    public void setClientId(Integer id) {
        this.id = id;
    }

    public Date getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(Date expiryDate) {
        this.expiryDate = expiryDate;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ATMCard)) {
            return false;
        }
        ATMCard other = (ATMCard) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.id + "";
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setApproved() {
        this.status = APPROVED;
    }

    public void setRejected() {
        this.status = REJECTED;
    }

    public String getCardNumber() {
        return cardNumber;
    }

    public void setCardNumber(String cardNumber) {
        this.cardNumber = cardNumber;
    }

    public String getPIN() {
        return PIN;
    }

    public void setPIN(String PIN) {
        this.PIN = PIN;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }

}
